package com.usermanagement.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.usermanagement.entity.UserDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper extends BaseMapper<UserDO> {

    @Select("SELECT * FROM users WHERE username = #{username} OR email = #{email}")
    UserDO selectByUsernameOrEmail(@Param("username") String username, @Param("email") String email);

    @Select("SELECT * FROM users WHERE user_id = #{userId}")
    UserDO selectByUserId(@Param("userId") Integer userId);

    @Select("SELECT COUNT(*) FROM user_roles WHERE role_id = #{roleId}")
    int countRoleById(@Param("roleId") Integer roleId);

    @Select("SELECT COUNT(*) FROM user_identities WHERE identity_id = #{identityId}")
    int countIdentityById(@Param("identityId") Integer identityId);
}